package com.lemon.smartsafetynew.ui.adapter.ledger;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafetynew.entity.patrol.SafePatrolGetTaskBo;
import com.lemon.smartsafetynew.entity.patrol.SafePatrolTaskVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2017/9/14.
 */

public class LedgerPatrolRecordAdapter extends LemonRcvAdapter<SafePatrolTaskVo> {

    public LedgerPatrolRecordAdapter(@Nullable List<SafePatrolTaskVo> data) {
        super(data);
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new ItemAdapter();
    }

    public class ItemAdapter implements AdapterItem<SafePatrolTaskVo> {

        @Bind(R.id.safe_patrol_task_name_tv)
        TextView safePatrolTaskNameTv;
        @Bind(R.id.safe_patrol_result_imageView)
        ImageView safePatrolResultImageView;
        @Bind(R.id.safe_patrol_worker_tv)
        TextView safePatrolWorkerTv;
        @Bind(R.id.safe_patrol_time_tv)
        TextView safePatrolTimeTv;
        @Bind(R.id.safe_patrol_task_layout)
        LinearLayout safePatrolTaskLayout;
        @Bind(R.id.safe_patrol_status_imageView)
        ImageView safePatrolStatusImageView;

        @Override
        public int getLayoutResId() {
            return R.layout.item_ledger_patrol_record;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
//            safePatrolTaskLayout.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//
//                }
//            });
        }

        @Override
        public void handleData(SafePatrolTaskVo safePatrolTaskVo, int position) {

            safePatrolTaskNameTv.setText(safePatrolTaskVo.getF_name());
            safePatrolWorkerTv.setText(safePatrolTaskVo.getUser_name());
            safePatrolTimeTv.setText(CommonUtil.timeToStr(safePatrolTaskVo.getPlan_start_time())
                    + " ~ " + CommonUtil.timeToStr(safePatrolTaskVo.getPlan_end_time()));

            if(SafePatrolGetTaskBo.Status.error.getValue().equals(safePatrolTaskVo.getF_status())) {
                safePatrolResultImageView.setVisibility(View.VISIBLE);
            } else {
                safePatrolResultImageView.setVisibility(View.GONE);
            }

            if (SafePatrolGetTaskBo.State.to_do.getValue().equals(safePatrolTaskVo.getF_state())) {
                safePatrolStatusImageView.setImageResource(R.mipmap.icon_ledger_patrol_not_do);
            } else if (SafePatrolGetTaskBo.State.doing.getValue().equals(safePatrolTaskVo.getF_state())) {
                safePatrolStatusImageView.setImageResource(R.mipmap.icon_ledger_patrol_doing);
            } else if (SafePatrolGetTaskBo.State.done.getValue().equals(safePatrolTaskVo.getF_state())) {
                safePatrolStatusImageView.setImageResource(R.mipmap.icon_ledger_patrol_done);
            } else if (SafePatrolGetTaskBo.State.over_time.getValue().equals(safePatrolTaskVo.getF_state())) {
                safePatrolStatusImageView.setImageResource(R.mipmap.icon_ledger_patrol_over_time);
            }
        }
    }
}
